Global Health and Development (2012-2021)

Baza danych zoostała pobrana z https://www.kaggle.com/datasets/martinagalasso/global-health-and-development-2012-2021?select=global_health.csv 9.12.2024

Zaimpotrowanie Biliotek

Bilioteka pycountry_convert odróżnia które państwa należą do danego kontynentu

Zainicjowanie pliku global_health.csv i przyjrzeniu się danym

In [1]:
import pandas as pd
import pycountry_convert as pc
import matplotlib.pyplot as plt

file_path = 'global_health.csv'
data = pd.read_csv(file_path)


print(data) 
          Country Country_Code  Year  Fertility_Rate  \
0     Afghanistan          AFG  2012           5.830   
1     Afghanistan          AFG  2013           5.696   
2     Afghanistan          AFG  2014           5.560   
3     Afghanistan          AFG  2015           5.405   
4     Afghanistan          AFG  2016           5.262   
...           ...          ...   ...             ...   
1875     Zimbabwe          ZWE  2017           3.706   
1876     Zimbabwe          ZWE  2018           3.659   
1877     Zimbabwe          ZWE  2019           3.599   
1878     Zimbabwe          ZWE  2020           3.545   
1879     Zimbabwe          ZWE  2021           3.491   

      Urban_Population_Percent  Total_Population  Water_Access_Percent  \
0                       24.160        30466479.0             21.123996   
1                       24.373        31541209.0             22.034470   
2                       24.587        32716210.0             22.944301   
3                       24.803        33753499.0             23.853590   
4                       25.020        34636207.0             24.762220   
...                        ...               ...                   ...   
1875                    32.237        14751101.0             26.944588   
1876                    32.209        15052184.0             26.807938   
1877                    32.210        15354608.0             26.683978   
1878                    32.242        15669666.0             26.573846   
1879                    32.303        15993524.0             26.476995   

      Unemployment_Rate  Sanitary_Expense_Per_GDP  Life_Expectancy  ...  \
0                 7.909                  7.897169           61.923  ...   
1                 7.919                  8.805964           62.417  ...   
2                 7.915                  9.528878           62.545  ...   
3                 9.011                 10.105348           62.659  ...   
4                10.100                 11.818590           63.136  ...   
...                 ...                       ...              ...  ...   
1875              6.347                  6.363583           60.709  ...   
1876              6.792                  4.670392           61.414  ...   
1877              7.373                  3.232802           61.292  ...   
1878              8.621                  2.954401           61.124  ...   
1879              9.540                  2.789751           59.253  ...   

      Sanitary_Expense_Per_Capita  CO2_Exposure_Percent  Air_Pollution  \
0                       52.613541             70.922317      70.922317   
1                       56.305542             73.131816      73.131816   
2                       60.189579             77.143728      77.143728   
3                       60.058540             73.490818      73.490818   
4                       61.486458             72.765910      72.765910   
...                           ...                   ...            ...   
1875                    92.254288             17.997754      17.997754   
1876                   114.632950             19.112099      19.112099   
1877                    54.808506             18.528607      18.528607   
1878                    50.676510             19.494180      19.494180   
1879                    62.737244                   NaN            NaN   

      Labour_Force_Total  Tuberculosis_Per_100000  Suicide_Rate_Percent  \
0              7520865.0                    189.0                  3.68   
1              7881567.0                    189.0                  3.66   
2              8285362.0                    189.0                  3.60   
3              8630724.0                    189.0                  3.57   
4              8913938.0                    189.0                  3.61   
...                  ...                      ...                   ...   
1875           5626689.0                    221.0                 15.02   
1876           5770751.0                    210.0                 14.00   
1877           5912685.0                    199.0                 14.12   
1878           6001349.0                    188.0                   NaN   
1879           6182422.0                    199.0                   NaN   

      Obesity_Rate_Percent  Underweight_Rate_Percent  Overweight_Rate_Percent  \
0                    10.70                     10.15                    31.55   
1                    11.55                     10.79                    32.73   
2                    10.44                     10.17                    33.95   
3                    11.19                     10.52                    35.19   
4                    11.99                      7.88                    36.45   
...                    ...                       ...                      ...   
1875                 10.27                      9.99                    17.43   
1876                 10.69                      5.18                    17.81   
1877                 11.11                      5.14                    18.22   
1878                 11.53                      5.11                    18.65   
1879                 11.97                      5.08                    19.11   

      Safe_Water_Access_Percent  
0                         46.68  
1                         49.45  
2                         52.25  
3                         55.09  
4                         57.97  
...                         ...  
1875                      50.06  
1876                      49.46  
1877                      48.87  
1878                      48.28  
1879                      47.70  

[1880 rows x 29 columns]

Wypisanie wszystkich kolumn w liście

In [2]:
data.columns.tolist()
Out[2]:
['Country',
 'Country_Code',
 'Year',
 'Fertility_Rate',
 'Urban_Population_Percent',
 'Total_Population',
 'Water_Access_Percent',
 'Unemployment_Rate',
 'Sanitary_Expense_Per_GDP',
 'Life_Expectancy',
 'Life_Expectancy_Female',
 'Life_Expectancy_Male',
 'Infant_Deaths',
 'GDP_Per_Capita',
 'Hospital_Beds_Per_1000',
 'Female_Population',
 'Male_Population',
 'Alcohol_Consumption_Per_Capita',
 'Immunization_Rate',
 'Sanitary_Expense_Per_Capita',
 'CO2_Exposure_Percent',
 'Air_Pollution',
 'Labour_Force_Total',
 'Tuberculosis_Per_100000',
 'Suicide_Rate_Percent',
 'Obesity_Rate_Percent',
 'Underweight_Rate_Percent',
 'Overweight_Rate_Percent',
 'Safe_Water_Access_Percent']

Wypisanie państw by zobaczyć jakie mają nazwy

In [3]:
unique_countries = data['Country'].unique()

unique_countries_count = len(unique_countries)

unique_countries_count, unique_countries
Out[3]:
(188,
 array(['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola',
        'Antigua and Barbuda', 'Argentina', 'Armenia', 'Australia',
        'Austria', 'Azerbaijan', 'Bahamas, The', 'Bahrain', 'Bangladesh',
        'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan',
        'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Brazil',
        'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi',
        'Cabo Verde', 'Cambodia', 'Cameroon', 'Canada',
        'Central African Republic', 'Chad', 'Chile', 'China', 'Colombia',
        'Comoros', 'Congo, Dem. Rep.', 'Congo, Rep.', 'Costa Rica',
        "Cote d'Ivoire", 'Croatia', 'Cuba', 'Cyprus', 'Czechia', 'Denmark',
        'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador',
        'Egypt, Arab Rep.', 'El Salvador', 'Equatorial Guinea', 'Eritrea',
        'Estonia', 'Eswatini', 'Ethiopia', 'Fiji', 'Finland', 'France',
        'Gabon', 'Gambia, The', 'Georgia', 'Germany', 'Ghana', 'Greece',
        'Grenada', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana',
        'Haiti', 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia',
        'Iran, Islamic Rep.', 'Iraq', 'Ireland', 'Israel', 'Italy',
        'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati',
        'Korea, Rep.', 'Kuwait', 'Kyrgyz Republic', 'Lao PDR', 'Latvia',
        'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein',
        'Lithuania', 'Luxembourg', 'Madagascar', 'Malawi', 'Malaysia',
        'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Mauritania',
        'Mauritius', 'Mexico', 'Micronesia, Fed. Sts.', 'Moldova',
        'Monaco', 'Mongolia', 'Montenegro', 'Morocco', 'Mozambique',
        'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands',
        'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'North Macedonia',
        'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama',
        'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Poland',
        'Portugal', 'Qatar', 'Romania', 'Russian Federation', 'Rwanda',
        'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia',
        'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore',
        'Slovak Republic', 'Slovenia', 'Solomon Islands', 'South Africa',
        'South Sudan', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Sweden',
        'Switzerland', 'Syrian Arab Republic', 'Tajikistan', 'Tanzania',
        'Thailand', 'Timor-Leste', 'Togo', 'Tonga', 'Trinidad and Tobago',
        'Tunisia', 'Turkiye', 'Turkmenistan', 'Tuvalu', 'Uganda',
        'Ukraine', 'United Arab Emirates', 'United Kingdom',
        'United States', 'Uruguay', 'Uzbekistan', 'Vanuatu',
        'Venezuela, RB', 'Viet Nam', 'Yemen, Rep.', 'Zambia', 'Zimbabwe'],
       dtype=object))

Przyporządkowanie kodu kontynentu do państwa

In [4]:
def get_continent(country_name):
    try:
        country_alpha2 = pc.country_name_to_country_alpha2(country_name)
        continent_code = pc.country_alpha2_to_continent_code(country_alpha2)
        return continent_code
    except KeyError:
        return "Unknown" 


data['Continent_Code'] = data['Country'].apply(get_continent)

data[['Country', 'Continent_Code']].head()
Out[4]:
Country Continent_Code
0 Afghanistan AS
1 Afghanistan AS
2 Afghanistan AS
3 Afghanistan AS
4 Afghanistan AS

Przyjżenie się czy nie brakuje danych

In [13]:
data.count()
Out[13]:
Country                           1880
Country_Code                      1880
Year                              1880
Fertility_Rate                    1844
Urban_Population_Percent          1880
Total_Population                  1880
Water_Access_Percent              1225
Unemployment_Rate                 1740
Sanitary_Expense_Per_GDP          1834
Life_Expectancy                   1840
Life_Expectancy_Female            1840
Life_Expectancy_Male              1840
Infant_Deaths                     1870
GDP_Per_Capita                    1853
Hospital_Beds_Per_1000            1281
Female_Population                 1880
Male_Population                   1880
Alcohol_Consumption_Per_Capita    1624
Immunization_Rate                 1870
Sanitary_Expense_Per_Capita       1833
CO2_Exposure_Percent              1683
Air_Pollution                     1683
Labour_Force_Total                1740
Tuberculosis_Per_100000           1670
Suicide_Rate_Percent              1272
Obesity_Rate_Percent              1650
Underweight_Rate_Percent          1650
Overweight_Rate_Percent           1650
Safe_Water_Access_Percent         1648
Continent_Code                    1880
dtype: int64

Z sumowanie ile jest pustych wartości w kolumnach

In [15]:
data.isnull().sum()
Out[15]:
Country                             0
Country_Code                        0
Year                                0
Fertility_Rate                     36
Urban_Population_Percent            0
Total_Population                    0
Water_Access_Percent              655
Unemployment_Rate                 140
Sanitary_Expense_Per_GDP           46
Life_Expectancy                    40
Life_Expectancy_Female             40
Life_Expectancy_Male               40
Infant_Deaths                      10
GDP_Per_Capita                     27
Hospital_Beds_Per_1000            599
Female_Population                   0
Male_Population                     0
Alcohol_Consumption_Per_Capita    256
Immunization_Rate                  10
Sanitary_Expense_Per_Capita        47
CO2_Exposure_Percent              197
Air_Pollution                     197
Labour_Force_Total                140
Tuberculosis_Per_100000           210
Suicide_Rate_Percent              608
Obesity_Rate_Percent              230
Underweight_Rate_Percent          230
Overweight_Rate_Percent           230
Safe_Water_Access_Percent         232
Continent_Code                      0
dtype: int64

Lista brakujących danych w kolumnie "Water_Access_Percent"

In [17]:
data[data['Water_Access_Percent'].isnull()]
Out[17]:
Country Country_Code Year Fertility_Rate Urban_Population_Percent Total_Population Water_Access_Percent Unemployment_Rate Sanitary_Expense_Per_GDP Life_Expectancy ... CO2_Exposure_Percent Air_Pollution Labour_Force_Total Tuberculosis_Per_100000 Suicide_Rate_Percent Obesity_Rate_Percent Underweight_Rate_Percent Overweight_Rate_Percent Safe_Water_Access_Percent Continent_Code
40 Angola AGO 2012 6.039 61.268 25188292.0 NaN 16.557 2.395750 58.623 ... 24.480493 24.480493 10527326.0 380.0 11.23 11.36 10.12 18.73 25.61 AF
41 Angola AGO 2013 5.953 62.002 26147002.0 NaN 16.487 2.732827 59.307 ... 24.538658 24.538658 10886364.0 376.0 11.31 11.70 9.97 19.04 25.98 AF
42 Angola AGO 2014 5.864 62.731 27128337.0 NaN 16.401 2.434129 60.040 ... 23.945584 23.945584 11251540.0 370.0 10.44 12.06 11.00 19.36 26.35 AF
43 Angola AGO 2015 5.774 63.446 28127721.0 NaN 16.491 2.605795 60.655 ... 25.002150 25.002150 11623549.0 366.0 10.46 12.44 10.82 19.67 26.71 AF
44 Angola AGO 2016 5.686 64.149 29154746.0 NaN 16.580 2.713150 61.092 ... 25.180701 25.180701 12011479.0 362.0 9.96 12.82 10.65 20.01 27.08 AF
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1865 Zambia ZMB 2017 4.614 42.976 17298054.0 NaN 8.518 4.781562 62.120 ... 23.758282 23.758282 5594492.0 361.0 13.63 11.12 10.54 16.66 47.73 AF
1866 Zambia ZMB 2018 4.536 43.521 17835893.0 NaN 5.031 4.769967 62.342 ... 23.336720 23.336720 5789287.0 346.0 13.23 11.74 10.19 17.33 48.86 AF
1867 Zambia ZMB 2019 4.451 44.072 18380477.0 NaN 5.539 6.753325 62.793 ... 23.203748 23.203748 6117559.0 333.0 12.01 12.38 8.07 18.03 49.99 AF
1868 Zambia ZMB 2020 4.379 44.629 18927715.0 NaN 6.032 6.316198 62.380 ... 24.308592 24.308592 6488754.0 319.0 NaN 13.04 7.93 18.77 51.12 AF
1869 Zambia ZMB 2021 4.308 45.192 19473125.0 NaN 5.195 6.624165 61.223 ... NaN NaN 6642413.0 307.0 NaN 13.72 7.80 19.54 51.12 AF

655 rows × 30 columns

Sprawdzenie ile zostanie danych po wykluczeniu wierszy z pustymi wartościami

In [19]:
data_noNA=data.dropna().copy()
In [21]:
data_noNA.count()
Out[21]:
Country                           669
Country_Code                      669
Year                              669
Fertility_Rate                    669
Urban_Population_Percent          669
Total_Population                  669
Water_Access_Percent              669
Unemployment_Rate                 669
Sanitary_Expense_Per_GDP          669
Life_Expectancy                   669
Life_Expectancy_Female            669
Life_Expectancy_Male              669
Infant_Deaths                     669
GDP_Per_Capita                    669
Hospital_Beds_Per_1000            669
Female_Population                 669
Male_Population                   669
Alcohol_Consumption_Per_Capita    669
Immunization_Rate                 669
Sanitary_Expense_Per_Capita       669
CO2_Exposure_Percent              669
Air_Pollution                     669
Labour_Force_Total                669
Tuberculosis_Per_100000           669
Suicide_Rate_Percent              669
Obesity_Rate_Percent              669
Underweight_Rate_Percent          669
Overweight_Rate_Percent           669
Safe_Water_Access_Percent         669
Continent_Code                    669
dtype: int64

Po wykluczeniu wierszy z pustymi wartościami baza zostaje okrojona do około 1/3 swej wielkości

Sprawdzenie przypisanie kodu kontynentu do państw

In [28]:
continent_counts = data['Continent_Code'].value_counts()


continent_counts
Out[28]:
Continent_Code
AF         480
EU         430
AS         400
NA         190
Unknown    140
OC         130
SA         110
Name: count, dtype: int64

Wyświetlenie których państw biblioteka nie rozpoznała

In [30]:
unknown_countries = data[data['Continent_Code'] == 'Unknown']['Country'].unique()

unknown_countries
Out[30]:
array(['Bahamas, The', 'Congo, Dem. Rep.', 'Congo, Rep.', "Cote d'Ivoire",
       'Egypt, Arab Rep.', 'Gambia, The', 'Iran, Islamic Rep.',
       'Korea, Rep.', 'Lao PDR', 'Micronesia, Fed. Sts.', 'Timor-Leste',
       'Turkiye', 'Venezuela, RB', 'Yemen, Rep.'], dtype=object)

Stworzenie listy i ręczne przypisanie państw do kontynentów

In [34]:
manual_continent_mapping = {
    'Bahamas, The': 'NA',
    'Congo, Dem. Rep.': 'AF',
    'Congo, Rep.': 'AF',
    "Cote d'Ivoire": 'AF',
    'Egypt, Arab Rep.': 'AF',
    'Gambia, The': 'AF',
    'Iran, Islamic Rep.': 'AS',
    'Korea, Rep.': 'AS',
    'Lao PDR': 'AS',
    'Micronesia, Fed. Sts.': 'OC',
    'Timor-Leste': 'OC',
    'Turkiye': 'AS',
    'Venezuela, RB': 'SA',
    'Yemen, Rep.': 'AS'
}


data['Continent_Code'] = data['Country'].apply(
    lambda x: manual_continent_mapping[x] if x in manual_continent_mapping else data.loc[data['Country'] == x, 'Continent_Code'].iloc[0]
)


data[data['Country'].isin(manual_continent_mapping.keys())][['Country', 'Continent_Code']]
Out[34]:
Country Continent_Code
110 Bahamas, The NA
111 Bahamas, The NA
112 Bahamas, The NA
113 Bahamas, The NA
114 Bahamas, The NA
... ... ...
1855 Yemen, Rep. AS
1856 Yemen, Rep. AS
1857 Yemen, Rep. AS
1858 Yemen, Rep. AS
1859 Yemen, Rep. AS

140 rows × 2 columns

Ponowne sprawdzenie czy wszytkie państwa mają przypisany kod kontynentu

In [36]:
continent_counts = data['Continent_Code'].value_counts()


continent_counts
Out[36]:
Continent_Code
AF    530
AS    450
EU    430
NA    200
OC    150
SA    120
Name: count, dtype: int64

Operacja na danych

Wyświetlenie przewidywanych życia ogólne, kobiet i mężczyzn w latach 2012-2021 dla każdego kontynentu

In [39]:
filtered_data = data[(data['Year'] >= 2012) & (data['Year'] <= 2021)]


grouped_data = filtered_data.groupby(['Continent_Code', 'Year'])[
    ['Life_Expectancy', 'Life_Expectancy_Female', 'Life_Expectancy_Male']
].mean().reset_index()


continents = [c for c in grouped_data['Continent_Code'].unique() if c != "Unknown"]


fig, axes = plt.subplots(3, 2, figsize=(15, 18))
axes = axes.flatten()

for i, continent in enumerate(continents[:6]): 
    continent_data = grouped_data[grouped_data['Continent_Code'] == continent]
    axes[i].plot(continent_data['Year'], continent_data['Life_Expectancy'], label='Life Expectancy')
    axes[i].plot(continent_data['Year'], continent_data['Life_Expectancy_Female'], label='Life Expectancy (Female)')
    axes[i].plot(continent_data['Year'], continent_data['Life_Expectancy_Male'], label='Life Expectancy (Male)')
    axes[i].set_title(f'Life Expectancy Trends in {continent} (2012-2021)')
    axes[i].set_xlabel('Year')
    axes[i].set_ylabel('Life Expectancy')
    axes[i].legend()
    axes[i].grid(True)


for j in range(len(continents), len(axes)):
    fig.delaxes(axes[j])

plt.tight_layout()
plt.show()
No description has been provided for this image

Wyświetlenie liczby ludności Polski i jej sąsiadów w latach 2012-2021 również z podziałem na liczbę kobiet i mężczyzn

In [122]:
poland_and_neighbors = [
    'Poland', 'Germany', 'Czechia', 'Slovak Republic',
    'Ukraine', 'Belarus', 'Lithuania', 'Russian Federation'
]

# Filtrowanie danych dla Polski i jej sąsiadów oraz lat 2012-2021
filtered_data = data[
    (data['Country'].isin(poland_and_neighbors)) &
    (data['Year'] >= 2012) & (data['Year'] <= 2021)
]

fig, axes = plt.subplots(10, 1, figsize=(30, 150), constrained_layout=True)
axes = axes.flatten()

years = range(2012, 2022)

for i, year in enumerate(years):
    ax = axes[i]
    year_data = filtered_data[filtered_data['Year'] == year]
    x = year_data['Country']

    
    bar_width = 0.25
    x_positions = range(len(x))

    bars_total = ax.bar(
        [p - bar_width for p in x_positions],
        year_data['Total_Population'], 
        width=bar_width, 
        label='Total Population'
    )
    bars_female = ax.bar(
        x_positions, 
        year_data['Female_Population'], 
        width=bar_width, 
        label='Female Population', 
        alpha=0.7
    )
    bars_male = ax.bar(
        [p + bar_width for p in x_positions], 
        year_data['Male_Population'], 
        width=bar_width, 
        label='Male Population', 
        alpha=0.7
    )

    
    for bar in bars_total + bars_female + bars_male:
        height = bar.get_height()
        ax.text(
            bar.get_x() + bar.get_width() / 2.0, 
            height/2, 
            f'{int(height):,}', 
            ha='center', 
            va='bottom', 
            fontsize=20, 
            rotation=90 
        )

   
    ax.set_title(f'Populacja Polski i jej sąsiadów w {year}', fontsize=50)
    ax.set_xlabel('Country', fontsize=40)
    ax.set_ylabel('Population', fontsize=40)
 
    ax.set_xticks(range(len(x)))  
    ax.set_xticklabels(x, rotation=45, ha='right', fontsize=30) 

    ax.legend(fontsize=20)
    ax.tick_params(axis='y', labelsize=20)  
    ax.yaxis.get_offset_text().set_fontsize(30)


for i in range(len(years), len(axes)):
    fig.delaxes(axes[i])

plt.show()
No description has been provided for this image

Pokazanie Top 10 w liczbie ludności na świecie na przestrzeni lat 2012-2021

In [134]:
# Filtrowanie danych dla lat 2012-2021
filtered_data = data[(data['Year'] >= 2012) & (data['Year'] <= 2021)]

# Grupowanie danych, aby znaleźć Top 10 dla każdego roku
top_10_each_year = (
    filtered_data.groupby('Year', group_keys=False)
    .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
)
# Podział danych top_10_each_year na poszczególne lata
years = filtered_data['Year'].unique()
top_10_each_year_dict = {
    year: top_10_each_year[top_10_each_year['Year'] == year] for year in years
}
top_10_each_year_dict
C:\Users\valen\AppData\Local\Temp\ipykernel_6320\2792410456.py:7: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
Out[134]:
{2012:       Year             Country  Total_Population
 350   2012               China      1.354190e+09
 760   2012               India      1.274487e+09
 1790  2012       United States      3.138777e+08
 770   2012           Indonesia      2.502227e+08
 1300  2012            Pakistan      2.022059e+08
 230   2012              Brazil      1.999777e+08
 1260  2012             Nigeria      1.700759e+08
 130   2012          Bangladesh      1.520906e+08
 1410  2012  Russian Federation      1.433784e+08
 840   2012               Japan      1.276290e+08,
 2013:       Year             Country  Total_Population
 351   2013               China      1.363240e+09
 761   2013               India      1.291132e+09
 1791  2013       United States      3.160599e+08
 771   2013           Indonesia      2.532759e+08
 1301  2013            Pakistan      2.053376e+08
 231   2013              Brazil      2.017218e+08
 1261  2013             Nigeria      1.747261e+08
 131   2013          Bangladesh      1.540301e+08
 1411  2013  Russian Federation      1.438056e+08
 841   2013               Japan      1.274450e+08,
 2014:       Year             Country  Total_Population
 352   2014               China      1.371860e+09
 762   2014               India      1.307247e+09
 1792  2014       United States      3.183863e+08
 772   2014           Indonesia      2.562298e+08
 1302  2014            Pakistan      2.082516e+08
 232   2014              Brazil      2.034596e+08
 1262  2014             Nigeria      1.793790e+08
 132   2014          Bangladesh      1.559613e+08
 1412  2014  Russian Federation      1.442372e+08
 842   2014               Japan      1.272760e+08,
 2015:       Year             Country  Total_Population
 353   2015               China      1.379860e+09
 763   2015               India      1.322867e+09
 1793  2015       United States      3.207390e+08
 773   2015           Indonesia      2.590920e+08
 1303  2015            Pakistan      2.109693e+08
 233   2015              Brazil      2.051882e+08
 1263  2015             Nigeria      1.839958e+08
 133   2015          Bangladesh      1.578300e+08
 1413  2015  Russian Federation      1.446407e+08
 843   2015               Japan      1.271410e+08,
 2016:       Year             Country  Total_Population
 354   2016               China      1.387790e+09
 764   2016               India      1.338636e+09
 1794  2016       United States      3.230718e+08
 774   2016           Indonesia      2.618502e+08
 1304  2016            Pakistan      2.135248e+08
 234   2016              Brazil      2.068596e+08
 1264  2016             Nigeria      1.886669e+08
 134   2016          Bangladesh      1.597846e+08
 1414  2016  Russian Federation      1.450155e+08
 844   2016               Japan      1.270760e+08,
 2017:       Year             Country  Total_Population
 355   2017               China      1.396215e+09
 765   2017               India      1.354196e+09
 1795  2017       United States      3.251221e+08
 775   2017           Indonesia      2.644989e+08
 1305  2017            Pakistan      2.163797e+08
 235   2017              Brazil      2.085050e+08
 1265  2017             Nigeria      1.934959e+08
 135   2017          Bangladesh      1.617940e+08
 1415  2017  Russian Federation      1.452933e+08
 845   2017               Japan      1.269720e+08,
 2018:       Year             Country  Total_Population
 356   2018               China      1.402760e+09
 766   2018               India      1.369003e+09
 1796  2018       United States      3.268382e+08
 776   2018           Indonesia      2.670668e+08
 1306  2018            Pakistan      2.197315e+08
 236   2018              Brazil      2.101666e+08
 1266  2018             Nigeria      1.983876e+08
 136   2018          Bangladesh      1.636840e+08
 1416  2018  Russian Federation      1.453981e+08
 846   2018               Japan      1.268110e+08,
 2019:       Year             Country  Total_Population
 357   2019               China      1.407745e+09
 767   2019               India      1.383112e+09
 1797  2019       United States      3.283300e+08
 777   2019           Indonesia      2.695829e+08
 1307  2019            Pakistan      2.232933e+08
 237   2019              Brazil      2.117829e+08
 1267  2019             Nigeria      2.033045e+08
 137   2019          Bangladesh      1.655162e+08
 1417  2019  Russian Federation      1.454533e+08
 847   2019               Japan      1.266330e+08,
 2020:       Year             Country  Total_Population
 358   2020               China      1.411100e+09
 768   2020               India      1.396387e+09
 1798  2020       United States      3.315269e+08
 778   2020           Indonesia      2.718580e+08
 1308  2020            Pakistan      2.271967e+08
 238   2020              Brazil      2.131963e+08
 1268  2020             Nigeria      2.083274e+08
 138   2020          Bangladesh      1.674210e+08
 1418  2020  Russian Federation      1.452451e+08
 848   2020               Japan      1.262610e+08,
 2021:       Year             Country  Total_Population
 359   2021               China      1.412360e+09
 769   2021               India      1.407564e+09
 1799  2021       United States      3.320490e+08
 779   2021           Indonesia      2.737532e+08
 1309  2021            Pakistan      2.314021e+08
 239   2021              Brazil      2.143262e+08
 1269  2021             Nigeria      2.134013e+08
 139   2021          Bangladesh      1.693563e+08
 1419  2021  Russian Federation      1.447468e+08
 1109  2021              Mexico      1.267051e+08}

Top 10 Liczby ludności dla Afryki

In [144]:
africa_data = data[(data['Continent_Code'] == 'AF') & (data['Year'] >= 2012) & (data['Year'] <= 2021)]

top_10_africa_each_year = (
    africa_data.groupby('Year', group_keys=False)
    .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
)

years_africa = filtered_data['Year'].unique()
top_10_africa_each_year_dict = {
    year: top_10_africa_each_year[top_10_africa_each_year['Year'] == year] for year in years
}
top_10_africa_each_year_dict
C:\Users\valen\AppData\Local\Temp\ipykernel_6320\2975718093.py:7: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
Out[144]:
{2012:       Year           Country  Total_Population
 1260  2012           Nigeria       170075932.0
 570   2012          Ethiopia        94451280.0
 510   2012  Egypt, Arab Rep.        91240376.0
 380   2012  Congo, Dem. Rep.        70997870.0
 1550  2012      South Africa        53145033.0
 1650  2012          Tanzania        47786137.0
 870   2012             Kenya        43725806.0
 20    2012           Algeria        37260563.0
 1590  2012             Sudan        35159792.0
 1750  2012            Uganda        34273295.0,
 2013:       Year           Country  Total_Population
 1261  2013           Nigeria       174726123.0
 571   2013          Ethiopia        97084366.0
 511   2013  Egypt, Arab Rep.        93377890.0
 381   2013  Congo, Dem. Rep.        73460021.0
 1551  2013      South Africa        53873616.0
 1651  2013          Tanzania        49253643.0
 871   2013             Kenya        44792368.0
 21    2013           Algeria        38000626.0
 1591  2013             Sudan        35990704.0
 1751  2013            Uganda        35273570.0,
 2014:       Year           Country  Total_Population
 1262  2014           Nigeria       179379016.0
 572   2014          Ethiopia        99746766.0
 512   2014  Egypt, Arab Rep.        95592324.0
 382   2014  Congo, Dem. Rep.        76035588.0
 1552  2014      South Africa        54729551.0
 1652  2014          Tanzania        50814552.0
 872   2014             Kenya        45831863.0
 22    2014           Algeria        38760168.0
 1592  2014             Sudan        37003245.0
 1752  2014            Uganda        36336539.0,
 2015:       Year           Country  Total_Population
 1263  2015           Nigeria       183995785.0
 573   2015          Ethiopia       102471895.0
 513   2015  Egypt, Arab Rep.        97723799.0
 383   2015  Congo, Dem. Rep.        78656904.0
 1553  2015      South Africa        55876504.0
 1653  2015          Tanzania        52542823.0
 873   2015             Kenya        46851488.0
 23    2015           Algeria        39543154.0
 1593  2015             Sudan        38171178.0
 1753  2015            Uganda        37477356.0,
 2016:       Year           Country  Total_Population
 1264  2016           Nigeria       188666931.0
 574   2016          Ethiopia       105293228.0
 514   2016  Egypt, Arab Rep.        99784030.0
 384   2016  Congo, Dem. Rep.        81430977.0
 1554  2016      South Africa        56422274.0
 1654  2016          Tanzania        54401802.0
 874   2016             Kenya        47894670.0
 24    2016           Algeria        40339329.0
 1594  2016             Sudan        39377169.0
 1754  2016            Uganda        38748299.0,
 2017:       Year           Country  Total_Population
 1265  2017           Nigeria       193495907.0
 575   2017          Ethiopia       108197950.0
 515   2017  Egypt, Arab Rep.       101789386.0
 385   2017  Congo, Dem. Rep.        84283273.0
 1555  2017      South Africa        56641209.0
 1655  2017          Tanzania        56267032.0
 875   2017             Kenya        48948137.0
 25    2017           Algeria        41136546.0
 1595  2017             Sudan        40679828.0
 1755  2017            Uganda        40127085.0,
 2018:       Year           Country  Total_Population
 1266  2018           Nigeria       198387623.0
 576   2018          Ethiopia       111129438.0
 516   2018  Egypt, Arab Rep.       103740765.0
 386   2018  Congo, Dem. Rep.        87087355.0
 1656  2018          Tanzania        58090443.0
 1556  2018      South Africa        57339635.0
 876   2018             Kenya        49953304.0
 1596  2018             Sudan        41999059.0
 26    2018           Algeria        41927007.0
 1756  2018            Uganda        41515395.0,
 2019:       Year           Country  Total_Population
 1267  2019           Nigeria       203304492.0
 577   2019          Ethiopia       114120594.0
 517   2019  Egypt, Arab Rep.       105618671.0
 387   2019  Congo, Dem. Rep.        89906890.0
 1657  2019          Tanzania        59872579.0
 1557  2019      South Africa        58087055.0
 877   2019             Kenya        50951450.0
 1597  2019             Sudan        43232093.0
 1757  2019            Uganda        42949080.0
 27    2019           Algeria        42705368.0,
 2020:       Year           Country  Total_Population
 1268  2020           Nigeria       208327405.0
 578   2020          Ethiopia       117190911.0
 518   2020  Egypt, Arab Rep.       107465134.0
 388   2020  Congo, Dem. Rep.        92853164.0
 1658  2020          Tanzania        61704518.0
 1558  2020      South Africa        58801927.0
 878   2020             Kenya        51985780.0
 1598  2020             Sudan        44440486.0
 1758  2020            Uganda        44404611.0
 28    2020           Algeria        43451666.0,
 2021:       Year           Country  Total_Population
 1269  2021           Nigeria       213401323.0
 579   2021          Ethiopia       120283026.0
 519   2021  Egypt, Arab Rep.       109262178.0
 389   2021  Congo, Dem. Rep.        95894118.0
 1659  2021          Tanzania        63588334.0
 1559  2021      South Africa        59392255.0
 879   2021             Kenya        53005614.0
 1759  2021            Uganda        45853778.0
 1599  2021             Sudan        45657202.0
 29    2021           Algeria        44177969.0}

Top 10 Liczby ludności dla Azji

In [148]:
asia_data = data[(data['Continent_Code'] == 'AS') & (data['Year'] >= 2012) & (data['Year'] <= 2021)]

top_10_asia_each_year = (
    asia_data.groupby('Year', group_keys=False)
    .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
)
years_asia = filtered_data['Year'].unique()
top_10_asia_each_year_dict = {
    year: top_10_asia_each_year[top_10_asia_each_year['Year'] == year] for year in years
}
top_10_asia_each_year_dict
C:\Users\valen\AppData\Local\Temp\ipykernel_6320\1338248896.py:7: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
Out[148]:
{2012:       Year             Country  Total_Population
 350   2012               China      1.354190e+09
 760   2012               India      1.274487e+09
 770   2012           Indonesia      2.502227e+08
 1300  2012            Pakistan      2.022059e+08
 130   2012          Bangladesh      1.520906e+08
 840   2012               Japan      1.276290e+08
 1360  2012         Philippines      9.803232e+07
 1840  2012            Viet Nam      8.930133e+07
 780   2012  Iran, Islamic Rep.      7.732445e+07
 1720  2012             Turkiye      7.517583e+07,
 2013:       Year             Country  Total_Population
 351   2013               China      1.363240e+09
 761   2013               India      1.291132e+09
 771   2013           Indonesia      2.532759e+08
 1301  2013            Pakistan      2.053376e+08
 131   2013          Bangladesh      1.540301e+08
 841   2013               Japan      1.274450e+08
 1361  2013         Philippines      9.970011e+07
 1841  2013            Viet Nam      9.026774e+07
 781   2013  Iran, Islamic Rep.      7.845893e+07
 1721  2013             Turkiye      7.614762e+07,
 2014:       Year             Country  Total_Population
 352   2014               China      1.371860e+09
 762   2014               India      1.307247e+09
 772   2014           Indonesia      2.562298e+08
 1302  2014            Pakistan      2.082516e+08
 132   2014          Bangladesh      1.559613e+08
 842   2014               Japan      1.272760e+08
 1362  2014         Philippines      1.013252e+08
 1842  2014            Viet Nam      9.123550e+07
 782   2014  Iran, Islamic Rep.      7.996167e+07
 1722  2014             Turkiye      7.718188e+07,
 2015:       Year             Country  Total_Population
 353   2015               China      1.379860e+09
 763   2015               India      1.322867e+09
 773   2015           Indonesia      2.590920e+08
 1303  2015            Pakistan      2.109693e+08
 133   2015          Bangladesh      1.578300e+08
 843   2015               Japan      1.271410e+08
 1363  2015         Philippines      1.030314e+08
 1843  2015            Viet Nam      9.219140e+07
 783   2015  Iran, Islamic Rep.      8.179084e+07
 1723  2015             Turkiye      7.821848e+07,
 2016:       Year             Country  Total_Population
 354   2016               China      1.387790e+09
 764   2016               India      1.338636e+09
 774   2016           Indonesia      2.618502e+08
 1304  2016            Pakistan      2.135248e+08
 134   2016          Bangladesh      1.597846e+08
 844   2016               Japan      1.270760e+08
 1364  2016         Philippines      1.048753e+08
 1844  2016            Viet Nam      9.312653e+07
 784   2016  Iran, Islamic Rep.      8.330623e+07
 1724  2016             Turkiye      7.927796e+07,
 2017:       Year             Country  Total_Population
 355   2017               China      1.396215e+09
 765   2017               India      1.354196e+09
 775   2017           Indonesia      2.644989e+08
 1305  2017            Pakistan      2.163797e+08
 135   2017          Bangladesh      1.617940e+08
 845   2017               Japan      1.269720e+08
 1365  2017         Philippines      1.067385e+08
 1845  2017            Viet Nam      9.403305e+07
 785   2017  Iran, Islamic Rep.      8.450508e+07
 1725  2017             Turkiye      8.031270e+07,
 2018:       Year             Country  Total_Population
 356   2018               China      1.402760e+09
 766   2018               India      1.369003e+09
 776   2018           Indonesia      2.670668e+08
 1306  2018            Pakistan      2.197315e+08
 136   2018          Bangladesh      1.636840e+08
 846   2018               Japan      1.268110e+08
 1366  2018         Philippines      1.085688e+08
 1846  2018            Viet Nam      9.491433e+07
 786   2018  Iran, Islamic Rep.      8.561756e+07
 1726  2018             Turkiye      8.140720e+07,
 2019:       Year             Country  Total_Population
 357   2019               China      1.407745e+09
 767   2019               India      1.383112e+09
 777   2019           Indonesia      2.695829e+08
 1307  2019            Pakistan      2.232933e+08
 137   2019          Bangladesh      1.655162e+08
 847   2019               Japan      1.266330e+08
 1367  2019         Philippines      1.103808e+08
 1847  2019            Viet Nam      9.577672e+07
 787   2019  Iran, Islamic Rep.      8.656420e+07
 1727  2019             Turkiye      8.257944e+07,
 2020:       Year             Country  Total_Population
 358   2020               China      1.411100e+09
 768   2020               India      1.396387e+09
 778   2020           Indonesia      2.718580e+08
 1308  2020            Pakistan      2.271967e+08
 138   2020          Bangladesh      1.674210e+08
 848   2020               Japan      1.262610e+08
 1368  2020         Philippines      1.121910e+08
 1848  2020            Viet Nam      9.664868e+07
 788   2020  Iran, Islamic Rep.      8.729019e+07
 1728  2020             Turkiye      8.338468e+07,
 2021:       Year             Country  Total_Population
 359   2021               China      1.412360e+09
 769   2021               India      1.407564e+09
 779   2021           Indonesia      2.737532e+08
 1309  2021            Pakistan      2.314021e+08
 139   2021          Bangladesh      1.693563e+08
 849   2021               Japan      1.256816e+08
 1369  2021         Philippines      1.138803e+08
 1849  2021            Viet Nam      9.746803e+07
 789   2021  Iran, Islamic Rep.      8.792343e+07
 1729  2021             Turkiye      8.414732e+07}

Top 10 Liczby ludności dla Europy

In [150]:
europe_data = data[(data['Continent_Code'] == 'EU') & (data['Year'] >= 2012) & (data['Year'] <= 2021)]

top_10_europe_each_year = (
    europe_data.groupby('Year', group_keys=False)
    .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
)

years_europe = filtered_data['Year'].unique()
top_10_europe_each_year_dict = {
    year: top_10_europe_each_year[top_10_europe_each_year['Year'] == year] for year in years
}
top_10_europe_each_year_dict
C:\Users\valen\AppData\Local\Temp\ipykernel_6320\318427.py:7: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
Out[150]:
{2012:       Year             Country  Total_Population
 1410  2012  Russian Federation       143378447.0
 640   2012             Germany        80425823.0
 600   2012              France        65662240.0
 1780  2012      United Kingdom        63700215.0
 820   2012               Italy        59539717.0
 1570  2012               Spain        46773055.0
 1760  2012             Ukraine        45593342.0
 1370  2012              Poland        38063164.0
 1400  2012             Romania        20058035.0
 1220  2012         Netherlands        16754962.0,
 2013:       Year             Country  Total_Population
 1411  2013  Russian Federation       143805638.0
 641   2013             Germany        80645605.0
 601   2013              France        66002289.0
 1781  2013      United Kingdom        64128273.0
 821   2013               Italy        60233948.0
 1571  2013               Spain        46620045.0
 1761  2013             Ukraine        45489648.0
 1371  2013              Poland        38040196.0
 1401  2013             Romania        19983693.0
 1221  2013         Netherlands        16804432.0,
 2014:       Year             Country  Total_Population
 1412  2014  Russian Federation       144237223.0
 642   2014             Germany        80982500.0
 602   2014              France        66312067.0
 1782  2014      United Kingdom        64602298.0
 822   2014               Italy        60789140.0
 1572  2014               Spain        46480882.0
 1762  2014             Ukraine        45272155.0
 1372  2014              Poland        38011735.0
 1402  2014             Romania        19908979.0
 1222  2014         Netherlands        16865008.0,
 2015:       Year             Country  Total_Population
 1413  2015  Russian Federation       144640716.0
 643   2015             Germany        81686611.0
 603   2015              France        66548272.0
 1783  2015      United Kingdom        65116219.0
 823   2015               Italy        60730582.0
 1573  2015               Spain        46444832.0
 1763  2015             Ukraine        45167350.0
 1373  2015              Poland        37986412.0
 1403  2015             Romania        19815616.0
 1223  2015         Netherlands        16939923.0,
 2016:       Year             Country  Total_Population
 1414  2016  Russian Federation       145015460.0
 644   2016             Germany        82348669.0
 604   2016              France        66724104.0
 1784  2016      United Kingdom        65611593.0
 824   2016               Italy        60627498.0
 1574  2016               Spain        46484062.0
 1764  2016             Ukraine        45038236.0
 1374  2016              Poland        37970087.0
 1404  2016             Romania        19702267.0
 1224  2016         Netherlands        17030314.0,
 2017:       Year             Country  Total_Population
 1415  2017  Russian Federation       145293260.0
 645   2017             Germany        82657002.0
 605   2017              France        66918020.0
 1785  2017      United Kingdom        66058859.0
 825   2017               Italy        60536709.0
 1575  2017               Spain        46593236.0
 1765  2017             Ukraine        44880758.0
 1375  2017              Poland        37974826.0
 1405  2017             Romania        19588715.0
 1225  2017         Netherlands        17131296.0,
 2018:       Year             Country  Total_Population
 1416  2018  Russian Federation       145398106.0
 646   2018             Germany        82905782.0
 606   2018              France        67158348.0
 1786  2018      United Kingdom        66460344.0
 826   2018               Italy        60421760.0
 1576  2018               Spain        46797754.0
 1766  2018             Ukraine        44690584.0
 1376  2018              Poland        37974750.0
 1406  2018             Romania        19473970.0
 1226  2018         Netherlands        17231624.0,
 2019:       Year             Country  Total_Population
 1417  2019  Russian Federation       145453291.0
 647   2019             Germany        83092962.0
 607   2019              France        67388001.0
 1787  2019      United Kingdom        66836327.0
 827   2019               Italy        59729081.0
 1577  2019               Spain        47134837.0
 1767  2019             Ukraine        44474512.0
 1377  2019              Poland        37965475.0
 1407  2019             Romania        19371648.0
 1227  2019         Netherlands        17344874.0,
 2020:       Year             Country  Total_Population
 1418  2020  Russian Federation       145245148.0
 648   2020             Germany        83160871.0
 608   2020              France        67571107.0
 1788  2020      United Kingdom        67081234.0
 828   2020               Italy        59438851.0
 1578  2020               Spain        47365655.0
 1768  2020             Ukraine        44207754.0
 1378  2020              Poland        37899070.0
 1408  2020             Romania        19265250.0
 1228  2020         Netherlands        17441500.0,
 2021:       Year             Country  Total_Population
 1419  2021  Russian Federation       144746762.0
 649   2021             Germany        83196078.0
 609   2021              France        67764304.0
 1789  2021      United Kingdom        67026292.0
 829   2021               Italy        59133173.0
 1579  2021               Spain        47415794.0
 1769  2021             Ukraine        43848986.0
 1379  2021              Poland        37747124.0
 1409  2021             Romania        19122059.0
 1229  2021         Netherlands        17533044.0}

Top 10 Liczby ludności dla Ameryki Północnej

In [160]:
NAmerica_data = data[(data['Continent_Code'] == 'NA') & (data['Year'] >= 2012) & (data['Year'] <= 2021)]


top_10_NAmerica_each_year = (
    NAmerica_data.groupby('Year', group_keys=False)
    .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
)

years_NAmerica = filtered_data['Year'].unique()
top_10_NAmerica_each_year_dict = {
    year: top_10_NAmerica_each_year[top_10_NAmerica_each_year['Year'] == year] for year in years
}
top_10_NAmerica_each_year_dict
C:\Users\valen\AppData\Local\Temp\ipykernel_6320\1161269664.py:7: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
Out[160]:
{2012:       Year             Country  Total_Population
 1790  2012       United States       313877662.0
 1100  2012              Mexico       115755909.0
 310   2012              Canada        34713395.0
 680   2012           Guatemala        14781942.0
 430   2012                Cuba        11309290.0
 720   2012               Haiti        10108539.0
 490   2012  Dominican Republic        10030882.0
 730   2012            Honduras         8792367.0
 520   2012         El Salvador         6161289.0
 1240  2012           Nicaragua         6030607.0,
 2013:       Year             Country  Total_Population
 1791  2013       United States       316059947.0
 1101  2013              Mexico       117290686.0
 311   2013              Canada        35080992.0
 681   2013           Guatemala        15043981.0
 431   2013                Cuba        11321579.0
 721   2013               Haiti        10261206.0
 491   2013  Dominican Republic        10157051.0
 731   2013            Honduras         8960657.0
 521   2013         El Salvador         6185642.0
 1241  2013           Nicaragua         6119379.0,
 2014:       Year             Country  Total_Population
 1792  2014       United States       318386329.0
 1102  2014              Mexico       118755887.0
 312   2014              Canada        35434066.0
 682   2014           Guatemala        15306316.0
 432   2014                Cuba        11332026.0
 722   2014               Haiti        10412740.0
 492   2014  Dominican Republic        10282115.0
 732   2014            Honduras         9127846.0
 522   2014         El Salvador         6209526.0
 1242  2014           Nicaragua         6208676.0,
 2015:       Year             Country  Total_Population
 1793  2015       United States       320738994.0
 1103  2015              Mexico       120149897.0
 313   2015              Canada        35704498.0
 683   2015           Guatemala        15567419.0
 433   2015                Cuba        11339894.0
 723   2015               Haiti        10563757.0
 493   2015  Dominican Republic        10405832.0
 733   2015            Honduras         9294505.0
 1243  2015           Nicaragua         6298598.0
 523   2015         El Salvador         6231066.0,
 2016:       Year             Country  Total_Population
 1794  2016       United States       323071755.0
 1104  2016              Mexico       121519221.0
 314   2016              Canada        36110803.0
 684   2016           Guatemala        15827690.0
 434   2016                Cuba        11342012.0
 724   2016               Haiti        10713849.0
 494   2016  Dominican Republic        10527592.0
 734   2016            Honduras         9460798.0
 1244  2016           Nicaragua         6389235.0
 524   2016         El Salvador         6250510.0,
 2017:       Year             Country  Total_Population
 1795  2017       United States       325122128.0
 1105  2017              Mexico       122839258.0
 315   2017              Canada        36545075.0
 685   2017           Guatemala        16087418.0
 435   2017                Cuba        11336405.0
 725   2017               Haiti        10863543.0
 495   2017  Dominican Republic        10647244.0
 735   2017            Honduras         9626842.0
 1245  2017           Nicaragua         6480532.0
 525   2017         El Salvador         6266654.0,
 2018:       Year             Country  Total_Population
 1796  2018       United States       326838199.0
 1106  2018              Mexico       124013861.0
 316   2018              Canada        37072620.0
 686   2018           Guatemala        16346950.0
 436   2018                Cuba        11328244.0
 726   2018               Haiti        11012421.0
 496   2018  Dominican Republic        10765531.0
 736   2018            Honduras         9792850.0
 1246  2018           Nicaragua         6572233.0
 526   2018         El Salvador         6276342.0,
 2019:       Year             Country  Total_Population
 1797  2019       United States       328329953.0
 1107  2019              Mexico       125085311.0
 317   2019              Canada        37618495.0
 687   2019           Guatemala        16604026.0
 437   2019                Cuba        11316697.0
 727   2019               Haiti        11160438.0
 497   2019  Dominican Republic        10881882.0
 737   2019            Honduras         9958829.0
 1247  2019           Nicaragua         6663924.0
 527   2019         El Salvador         6280217.0,
 2020:       Year             Country  Total_Population
 1798  2020       United States       331526933.0
 1108  2020              Mexico       125998302.0
 318   2020              Canada        38028638.0
 688   2020           Guatemala        16858333.0
 728   2020               Haiti        11306801.0
 438   2020                Cuba        11300698.0
 498   2020  Dominican Republic        10999664.0
 738   2020            Honduras        10121763.0
 1248  2020           Nicaragua         6755895.0
 528   2020         El Salvador         6292731.0,
 2021:       Year             Country  Total_Population
 1799  2021       United States       332048977.0
 1109  2021              Mexico       126705138.0
 319   2021              Canada        38239864.0
 689   2021           Guatemala        17109746.0
 729   2021               Haiti        11447569.0
 439   2021                Cuba        11256372.0
 499   2021  Dominican Republic        11117873.0
 739   2021            Honduras        10278345.0
 1249  2021           Nicaragua         6850540.0
 529   2021         El Salvador         6314167.0}

Top 10 Liczby ludności dla Oceanii

In [162]:
oceania_data = data[(data['Continent_Code'] == 'OC') & (data['Year'] >= 2012) & (data['Year'] <= 2021)]

top_10_oceania_each_year = (
    oceania_data.groupby('Year', group_keys=False)
    .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
)

years_oceania = filtered_data['Year'].unique()
top_10_oceania_each_year_dict = {
    year: top_10_oceania_each_year[top_10_oceania_each_year['Year'] == year] for year in years
}
top_10_oceania_each_year_dict
C:\Users\valen\AppData\Local\Temp\ipykernel_6320\1565466495.py:7: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
Out[162]:
{2012:       Year                Country  Total_Population
 80    2012              Australia        22733465.0
 1330  2012       Papua New Guinea         8026545.0
 1230  2012            New Zealand         4408100.0
 1670  2012            Timor-Leste         1137676.0
 580   2012                   Fiji          911059.0
 1540  2012        Solomon Islands          567763.0
 1820  2012                Vanuatu          257313.0
 1430  2012                  Samoa          198124.0
 880   2012               Kiribati          111618.0
 1110  2012  Micronesia, Fed. Sts.          108232.0,
 2013:       Year                Country  Total_Population
 81    2013              Australia        23128129.0
 1331  2013       Papua New Guinea         8245627.0
 1231  2013            New Zealand         4442100.0
 1671  2013            Timor-Leste         1161555.0
 581   2013                   Fiji          913453.0
 1541  2013        Solomon Islands          582365.0
 1821  2013                Vanuatu          263534.0
 1431  2013                  Samoa          199939.0
 881   2013               Kiribati          113311.0
 1111  2013  Micronesia, Fed. Sts.          108609.0,
 2014:       Year                Country  Total_Population
 82    2014              Australia        23475686.0
 1332  2014       Papua New Guinea         8464153.0
 1232  2014            New Zealand         4516500.0
 1672  2014            Timor-Leste         1184830.0
 582   2014                   Fiji          915560.0
 1542  2014        Solomon Islands          597375.0
 1822  2014                Vanuatu          269927.0
 1432  2014                  Samoa          201757.0
 882   2014               Kiribati          114985.0
 1112  2014  Micronesia, Fed. Sts.          109024.0,
 2015:       Year                Country  Total_Population
 83    2015              Australia        23815995.0
 1333  2015       Papua New Guinea         8682174.0
 1233  2015            New Zealand         4609400.0
 1673  2015            Timor-Leste         1205813.0
 583   2015                   Fiji          917200.0
 1543  2015        Solomon Islands          612660.0
 1823  2015                Vanuatu          276438.0
 1433  2015                  Samoa          203571.0
 883   2015               Kiribati          116707.0
 1113  2015  Micronesia, Fed. Sts.          109462.0,
 2016:       Year                Country  Total_Population
 84    2016              Australia        24190907.0
 1334  2016       Papua New Guinea         8899169.0
 1234  2016            New Zealand         4714100.0
 1674  2016            Timor-Leste         1224562.0
 584   2016                   Fiji          918371.0
 1544  2016        Solomon Islands          628102.0
 1824  2016                Vanuatu          283218.0
 1434  2016                  Samoa          205544.0
 884   2016               Kiribati          118513.0
 1114  2016  Micronesia, Fed. Sts.          109925.0,
 2017:       Year                Country  Total_Population
 85    2017              Australia        24592588.0
 1335  2017       Papua New Guinea         9114796.0
 1235  2017            New Zealand         4813600.0
 1675  2017            Timor-Leste         1243235.0
 585   2017                   Fiji          919019.0
 1545  2017        Solomon Islands          643634.0
 1825  2017                Vanuatu          290239.0
 1435  2017                  Samoa          207630.0
 885   2017               Kiribati          120362.0
 1115  2017  Micronesia, Fed. Sts.          110430.0,
 2018:       Year                Country  Total_Population
 86    2018              Australia        24963258.0
 1336  2018       Papua New Guinea         9329227.0
 1236  2018            New Zealand         4900600.0
 1676  2018            Timor-Leste         1261845.0
 586   2018                   Fiji          918996.0
 1546  2018        Solomon Islands          659249.0
 1826  2018                Vanuatu          297298.0
 1436  2018                  Samoa          209701.0
 886   2018               Kiribati          122261.0
 1116  2018  Micronesia, Fed. Sts.          110929.0,
 2019:       Year                Country  Total_Population
 87    2019              Australia        25334826.0
 1337  2019       Papua New Guinea         9542486.0
 1237  2019            New Zealand         4979200.0
 1677  2019            Timor-Leste         1280438.0
 587   2019                   Fiji          918465.0
 1547  2019        Solomon Islands          674993.0
 1827  2019                Vanuatu          304404.0
 1437  2019                  Samoa          211905.0
 887   2019               Kiribati          124241.0
 1117  2019  Micronesia, Fed. Sts.          111379.0,
 2020:       Year                Country  Total_Population
 88    2020              Australia        25649248.0
 1338  2020       Papua New Guinea         9749640.0
 1238  2020            New Zealand         5090200.0
 1678  2020            Timor-Leste         1299995.0
 588   2020                   Fiji          920422.0
 1548  2020        Solomon Islands          691191.0
 1828  2020                Vanuatu          311685.0
 1438  2020                  Samoa          214929.0
 888   2020               Kiribati          126463.0
 1118  2020  Micronesia, Fed. Sts.          112106.0,
 2021:       Year                Country  Total_Population
 89    2021              Australia        25685412.0
 1339  2021       Papua New Guinea         9949437.0
 1239  2021            New Zealand         5111300.0
 1679  2021            Timor-Leste         1320942.0
 589   2021                   Fiji          924610.0
 1549  2021        Solomon Islands          707851.0
 1829  2021                Vanuatu          319137.0
 1439  2021                  Samoa          218764.0
 889   2021               Kiribati          128874.0
 1119  2021  Micronesia, Fed. Sts.          113131.0}

Top 10 Liczby ludności dla Ameryki Południowej

In [166]:
SAmerica_data = data[(data['Continent_Code'] == 'SA') & (data['Year'] >= 2012) & (data['Year'] <= 2021)]


top_10_SAmerica_each_year = (
    SAmerica_data.groupby('Year', group_keys=False)
    .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
)

years_SAmerica = filtered_data['Year'].unique()
top_10_SAmerica_each_year_dict = {
    year: top_10_SAmerica_each_year[top_10_SAmerica_each_year['Year'] == year] for year in years
}
top_10_SAmerica_each_year_dict
C:\Users\valen\AppData\Local\Temp\ipykernel_6320\3321158501.py:7: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda x: x.nlargest(10, 'Total_Population')[['Year', 'Country', 'Total_Population']])
Out[166]:
{2012:       Year        Country  Total_Population
 230   2012         Brazil       199977707.0
 360   2012       Colombia        45782417.0
 60    2012      Argentina        41733271.0
 1350  2012           Peru        29749589.0
 1830  2012  Venezuela, RB        29470426.0
 340   2012          Chile        17341771.0
 500   2012        Ecuador        15483883.0
 200   2012        Bolivia        10569697.0
 1340  2012       Paraguay         5923322.0
 1800  2012        Uruguay         3371133.0,
 2013:       Year        Country  Total_Population
 231   2013         Brazil       201721767.0
 361   2013       Colombia        46237930.0
 61    2013      Argentina        42202935.0
 1351  2013           Peru        30038809.0
 1831  2013  Venezuela, RB        29838021.0
 341   2013          Chile        17509925.0
 501   2013        Ecuador        15722989.0
 201   2013        Bolivia        10743349.0
 1341  2013       Paraguay         6005652.0
 1801  2013        Uruguay         3381180.0,
 2014:       Year        Country  Total_Population
 232   2014         Brazil       203459650.0
 362   2014       Colombia        46677947.0
 62    2014      Argentina        42669500.0
 1352  2014           Peru        30353951.0
 1832  2014  Venezuela, RB        30193258.0
 342   2014          Chile        17687108.0
 502   2014        Ecuador        15957994.0
 202   2014        Bolivia        10916987.0
 1342  2014       Paraguay         6090721.0
 1802  2014        Uruguay         3391662.0,
 2015:       Year        Country  Total_Population
 233   2015         Brazil       205188205.0
 363   2015       Colombia        47119728.0
 63    2015      Argentina        43131966.0
 1353  2015           Peru        30711863.0
 1833  2015  Venezuela, RB        30529716.0
 343   2015          Chile        17870124.0
 503   2015        Ecuador        16195902.0
 203   2015        Bolivia        11090085.0
 1343  2015       Paraguay         6177950.0
 1803  2015        Uruguay         3402818.0,
 2016:       Year        Country  Total_Population
 234   2016         Brazil       206859578.0
 364   2016       Colombia        47625955.0
 64    2016      Argentina        43590368.0
 1354  2016           Peru        31132779.0
 1834  2016  Venezuela, RB        30741464.0
 344   2016          Chile        18083879.0
 504   2016        Ecuador        16439585.0
 204   2016        Bolivia        11263015.0
 1344  2016       Paraguay         6266615.0
 1804  2016        Uruguay         3413766.0,
 2017:       Year        Country  Total_Population
 235   2017         Brazil       208504960.0
 365   2017       Colombia        48351671.0
 65    2017      Argentina        44044811.0
 1355  2017           Peru        31605486.0
 1835  2017  Venezuela, RB        30563433.0
 345   2017          Chile        18368577.0
 505   2017        Ecuador        16696944.0
 205   2017        Bolivia        11435533.0
 1345  2017       Paraguay         6355404.0
 1805  2017        Uruguay         3422200.0,
 2018:       Year        Country  Total_Population
 236   2018         Brazil       210166592.0
 366   2018       Colombia        49276961.0
 66    2018      Argentina        44494502.0
 1356  2018           Peru        32203944.0
 1836  2018  Venezuela, RB        29825653.0
 346   2018          Chile        18701450.0
 506   2018        Ecuador        17015672.0
 206   2018        Bolivia        11606905.0
 1346  2018       Paraguay         6443328.0
 1806  2018        Uruguay         3427042.0,
 2019:       Year        Country  Total_Population
 237   2019         Brazil       211782878.0
 367   2019       Colombia        50187406.0
 67    2019      Argentina        44938712.0
 1357  2019           Peru        32824861.0
 1837  2019  Venezuela, RB        28971683.0
 347   2019          Chile        19039485.0
 507   2019        Ecuador        17343740.0
 207   2019        Bolivia        11777315.0
 1347  2019       Paraguay         6530026.0
 1807  2019        Uruguay         3428409.0,
 2020:       Year        Country  Total_Population
 238   2020         Brazil       213196304.0
 368   2020       Colombia        50930662.0
 68    2020      Argentina        45376763.0
 1358  2020           Peru        33304756.0
 1838  2020  Venezuela, RB        28490453.0
 348   2020          Chile        19300315.0
 508   2020        Ecuador        17588595.0
 208   2020        Bolivia        11936162.0
 1348  2020       Paraguay         6618695.0
 1808  2020        Uruguay         3429086.0,
 2021:       Year        Country  Total_Population
 239   2021         Brazil       214326223.0
 369   2021       Colombia        51516562.0
 69    2021      Argentina        45808747.0
 1359  2021           Peru        33715471.0
 1839  2021  Venezuela, RB        28199867.0
 349   2021          Chile        19493184.0
 509   2021        Ecuador        17797737.0
 209   2021        Bolivia        12079472.0
 1349  2021       Paraguay         6703799.0
 1809  2021        Uruguay         3426260.0}
In [ ]:
 

Wydatki sanitarne na PKB %

In [193]:
continents = {
    'AF': 'Africa',
    'EU': 'Europe',
    'AS': 'Asia',
    'NA': 'North America',
    'SA': 'South America',
    'OC': 'Oceania'
}


fig, axes = plt.subplots(6, 1, figsize=(18, 72), constrained_layout=True)
axes = axes.flatten()

for idx, (continent_code, continent_name) in enumerate(continents.items()):
    
    continent_data = data[data['Continent_Code'] == continent_code]
    
    
    avg_sanitary_expense = (
        continent_data.groupby('Country')['Sanitary_Expense_Per_GDP'].mean().reset_index()
    )
    
    
    top_10_countries = avg_sanitary_expense.sort_values(
        by='Sanitary_Expense_Per_GDP', ascending=False
    ).head(10)
    
    
    top_countries_data = data[
        (data['Country'].isin(top_10_countries['Country'])) &
        (data['Continent_Code'] == continent_code)
    ]
    
    
    ax = axes[idx]
    for country in top_10_countries['Country']:
        country_data = top_countries_data[top_countries_data['Country'] == country]
        ax.plot(
            country_data['Year'], 
            country_data['Sanitary_Expense_Per_GDP'], 
            label=country
        )
    
   
    ax.set_title(f'Sanitary Expense (% GDP) in {continent_name}', fontsize=42)
    ax.set_xlabel('Year', fontsize=36)
    ax.set_ylabel('Sanitary Expense (% GDP)', fontsize=36)
   
    ax.tick_params(axis='x', labelsize=14)  
    ax.tick_params(axis='y', labelsize=14)  

    ax.legend(fontsize=16, loc='upper left')
    ax.grid(True)


for idx in range(len(continents), len(axes)):
    fig.delaxes(axes[idx])

plt.show()
No description has been provided for this image

Ile przypada łóżek szpitalnych na 1000 osób w top 10 państwach na kontynentach

In [332]:
fig, axes = plt.subplots(6, 1, figsize=(12, 30), constrained_layout=True)
axes = axes.flatten()

for idx, (continent_code, continent_name) in enumerate(continents.items()):
    
    continent_data = data[data['Continent_Code'] == continent_code]
    
    
    countries_with_full_data = continent_data.groupby('Country').filter(
        lambda x: x['Hospital_Beds_Per_1000'].notna().sum() == 10
    )['Country'].unique()
    
    
    avg_hospital_beds = (
        continent_data[continent_data['Country'].isin(countries_with_full_data)]
        .groupby('Country')['Hospital_Beds_Per_1000']
        .mean()
        .reset_index()
    )
    
    
    top_10_countries = avg_hospital_beds.sort_values(
        by='Hospital_Beds_Per_1000', ascending=False
    ).head(10)
    
    
    top_countries_data = data[
        (data['Country'].isin(top_10_countries['Country'])) & 
        (data['Continent_Code'] == continent_code)
    ]
    
    
    ax = axes[idx]
    for country in top_10_countries['Country']:
        country_data = top_countries_data[top_countries_data['Country'] == country]
        ax.plot(
            country_data['Year'], 
            country_data['Hospital_Beds_Per_1000'], 
            label=country
        )
    
    
    ax.set_title(f'Hospital Beds per 1000 in {continent_name}', fontsize=14)
    ax.set_xlabel('Year', fontsize=12)
    ax.set_ylabel('Beds per 1000', fontsize=12)
    ax.tick_params(axis='x', labelsize=12)
    ax.tick_params(axis='y', labelsize=12)
    ax.legend(fontsize=8, loc='upper left')
    ax.grid(True)

plt.show()
No description has been provided for this image

Zwizualizowanie top 10 państw w poziomie zaszczepienia z podziałem na kontynenty

In [237]:
fig, axes = plt.subplots(6, 1, figsize=(12, 30), constrained_layout=True)
axes = axes.flatten()

for idx, (continent_code, continent_name) in enumerate(continents.items()):
    
    continent_data = data[data['Continent_Code'] == continent_code]
    
    
    avg_immunization_rate = (
        continent_data.groupby('Country')['Immunization_Rate']
        .mean()
        .reset_index()
    )
    
    
    top_10_countries = avg_immunization_rate.sort_values(
        by='Immunization_Rate', ascending=False
    ).head(10)
    
    
    top_countries_data = data[
        (data['Country'].isin(top_10_countries['Country'])) & 
        (data['Continent_Code'] == continent_code)
    ]
    
    
    ax = axes[idx]
    years = sorted(top_countries_data['Year'].unique())
    countries = top_10_countries['Country']
    bar_width = 0.07
    x_positions = range(len(years))

    for i, country in enumerate(countries):
        country_data = top_countries_data[top_countries_data['Country'] == country]
        ax.bar(
            [x + (i * bar_width) for x in x_positions], 
            country_data['Immunization_Rate'], 
            width=bar_width, 
            label=country
        )
    
    
    ax.set_title(f'Immunization Rate in {continent_name}', fontsize=14)
    ax.set_xlabel('Year', fontsize=12)
    ax.set_ylabel('Immunization Rate', fontsize=12)
    ax.set_xticks([x + (len(countries) * bar_width) / 2 for x in x_positions])
    ax.set_xticklabels(years)
    ax.tick_params(axis='x', labelsize=10, rotation=45)
    ax.tick_params(axis='y', labelsize=12)
    ax.legend(fontsize=8, loc='lower left')
    ax.grid(True)

plt.show()
No description has been provided for this image

Zwizualizowanie 5 losowych państw w poziomie zaszczepienia z podziałem na kontynenty

In [238]:
fig, axes = plt.subplots(6, 1, figsize=(14, 40), constrained_layout=True)
axes = axes.flatten()

for idx, (continent_code, continent_name) in enumerate(continents.items()):
    
    continent_data = data[data['Continent_Code'] == continent_code]
    
    
    selected_countries = continent_data['Country'].drop_duplicates().sample(5, random_state=42)
    
    selected_data = continent_data[continent_data['Country'].isin(selected_countries)]
    
    
    ax = axes[idx]
    years = sorted(selected_data['Year'].unique())
    bar_width = 0.15
    x_positions = range(len(years))

    for i, country in enumerate(selected_countries):
        country_data = selected_data[selected_data['Country'] == country]
        ax.bar(
            [x + (i * bar_width) for x in x_positions], 
            country_data['Immunization_Rate'], 
            width=bar_width, 
            label=country
        )
    
    ax.set_title(f'Immunization Rate in {continent_name}', fontsize=16)
    ax.set_xlabel('Year', fontsize=14)
    ax.set_ylabel('Immunization Rate', fontsize=14)
    ax.set_xticks([x + (len(selected_countries) * bar_width) / 2 for x in x_positions])
    ax.set_xticklabels(years, fontsize=12, rotation=45)
    ax.tick_params(axis='y', labelsize=12)
    ax.legend(fontsize=12, loc='lower left')
    ax.grid(axis='y', linestyle='--', alpha=0.7)

plt.show()
No description has been provided for this image

Pokazanie procenta bezrobocia w Europie, porówannie roku 2012 z 2021 z wyróżnieniem Polski na wykresach

In [265]:
europe_data = data[(data['Continent_Code'] == 'EU') & (data['Year'].isin([2012, 2021]))]

fig, axes = plt.subplots(2, 1, figsize=(12, 14), constrained_layout=True)

for i, year in enumerate([2012, 2021]):
    year_data = europe_data[europe_data['Year'] == year]
    
    
    sorted_data = year_data[['Country', 'Unemployment_Rate']].dropna().sort_values(by='Unemployment_Rate', ascending=False)
    
    
    colors = []
    for _, row in sorted_data.iterrows():
        if row['Country'] == 'Poland':
            if row['Unemployment_Rate'] > 10:
                colors.append('darkred')  
            elif 5 <= row['Unemployment_Rate'] <= 10:
                colors.append('darkgoldenrod')  
            else:
                colors.append('darkgreen')  
        else:
            if row['Unemployment_Rate'] > 10:
                colors.append('red')  
            elif 5 <= row['Unemployment_Rate'] <= 10:
                colors.append('yellow')  
            else:
                colors.append('green')  
    
    
    ax = axes[i]
    bars = ax.barh(sorted_data['Country'], sorted_data['Unemployment_Rate'], color=colors)
    ax.set_title(f'Unemployment Rate in Europe ({year})', fontsize=16)
    ax.set_xlabel('Unemployment Rate (%)', fontsize=14)
    ax.set_ylabel('Country', fontsize=14)
    ax.invert_yaxis()  
    ax.grid(axis='x', linestyle='--', alpha=0.7)

    
    for bar in bars:
        ax.text(
            bar.get_width() + 0.5,  
            bar.get_y() + bar.get_height() / 2,  
            f'{bar.get_width():.1f}%',  
            va='center', 
            fontsize=10
        )

plt.show()
No description has been provided for this image

Pokazanie Procentu otyłości, niedowagi i nadwagi w Ameryce Północnej w 2021 roku

In [291]:
north_america_data = data[(data['Continent_Code'] == 'NA')]


variables = ['Obesity_Rate_Percent', 'Underweight_Rate_Percent', 'Overweight_Rate_Percent']
north_america_filtered = north_america_data.dropna(subset=variables)

latest_year = north_america_filtered['Year'].max()
latest_data = north_america_filtered[north_america_filtered['Year'] == latest_year]

fig, axes = plt.subplots(len(variables), 1, figsize=(12, 18), constrained_layout=True)
axes = axes.flatten()

for idx, variable in enumerate(variables):
    ax = axes[idx]
    sorted_data = latest_data[['Country', variable]].sort_values(by=variable, ascending=False)
    
    bars = ax.barh(sorted_data['Country'], sorted_data[variable], color='blue')
    
   
    for bar in bars:
        ax.text(
            bar.get_width() + 0.5,  
            bar.get_y() + bar.get_height() / 2,  
            f'{bar.get_width():.1f}',  
            va='center', 
            fontsize=10
        )
    
    
    ax.set_title(f'{variable.replace("_", " ")} in North America ({latest_year})', fontsize=14)
    ax.set_xlabel(variable.replace("_", " "), fontsize=12)
    ax.set_ylabel('Country', fontsize=12)
    ax.invert_yaxis()  
    ax.grid(axis='x', linestyle='--', alpha=0.7)

plt.show()
No description has been provided for this image

Pokazanie średniej samobójstw przypadjącą na kontynet w 2012

In [380]:
data_2012 = data[(data['Year'] == 2012) & (data['Suicide_Rate_Percent'].notna())]


continent_suicide_rate = data_2012.groupby('Continent_Code')['Suicide_Rate_Percent'].mean().reset_index()


labels = continent_suicide_rate['Continent_Code']
sizes = continent_suicide_rate['Suicide_Rate_Percent']


plt.figure(figsize=(10, 6))
bars = plt.bar(labels, sizes, color=['#ff9999' if label == 'EU' else '#66b3ff' for label in labels])
plt.title('Average Suicide Rate Percent by Continent (2012)', fontsize=16)
plt.xlabel('Continent', fontsize=14)
plt.ylabel('Average Suicide Rate Percent', fontsize=14)


for bar in bars:
    plt.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 0.1, 
             f'{bar.get_height():.1f}', ha='center', fontsize=12)

plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.show()
No description has been provided for this image

Pokazanie globalnego % wszystkich samobójstw na kontynet w 2012

In [399]:
data_2012 = data[(data['Year'] == 2012) & (data['Suicide_Rate_Percent'].notna())]


continent_suicide_rate = data_2012.groupby('Continent_Code')['Suicide_Rate_Percent'].mean().reset_index()


labels = [
    f"{label} ({value:.1f}%)"
    for label, value in zip(continent_suicide_rate['Continent_Code'], continent_suicide_rate['Suicide_Rate_Percent'])
]
sizes = continent_suicide_rate['Suicide_Rate_Percent']
explode = [0.2 if label.startswith('EU') else 0 for label in labels]  


plt.figure(figsize=(10, 8))
plt.pie(sizes, labels=labels, autopct='%1.1f%%', explode=explode, startangle=140, colors=['#ff9999', '#66b3ff', '#99ff99', '#ffcc99', '#c2c2f0', '#ffb3e6'])
plt.title('Percentage of Global Suicides by Continent (2012)', fontsize=16)
plt.show()
No description has been provided for this image

Pokazanie top 10 państw z największym % samobójstwa

In [378]:
europe_data_2012 = data[
    (data['Continent_Code'] == 'EU') & 
    (data['Year'] == 2012) & 
    (data['Suicide_Rate_Percent'].notna())
]


top_10_suicide_rate = europe_data_2012.nlargest(10, 'Suicide_Rate_Percent')[['Country', 'Suicide_Rate_Percent']]

top_10_suicide_rate
Out[378]:
Country Suicide_Rate_Percent
930 Latvia 23.53
1760 Ukraine 23.11
1530 Slovenia 21.95
550 Estonia 21.09
1370 Poland 18.51
420 Croatia 18.39
1480 Serbia 18.22
600 France 17.78
590 Finland 16.95
450 Czechia 16.70

Pokazanie średniej samobójstw przypadjącą na kontynet w 2019

In [382]:
data_2019 = data[(data['Year'] == 2019) & (data['Suicide_Rate_Percent'].notna())]


continent_suicide_rate = data_2019.groupby('Continent_Code')['Suicide_Rate_Percent'].mean().reset_index()


labels = continent_suicide_rate['Continent_Code']
sizes = continent_suicide_rate['Suicide_Rate_Percent']


plt.figure(figsize=(10, 6))
bars = plt.bar(labels, sizes, color=['#ff9999' if label == 'EU' else '#66b3ff' for label in labels])
plt.title('Average Suicide Rate Percent by Continent (2019)', fontsize=16)
plt.xlabel('Continent', fontsize=14)
plt.ylabel('Average Suicide Rate Percent', fontsize=14)


for bar in bars:
    plt.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 0.1, 
             f'{bar.get_height():.1f}', ha='center', fontsize=12)

plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.show()
No description has been provided for this image

Pokazanie globalnego % wszystkich samobójstw na kontynet w 2019

In [410]:
data_2019 = data[(data['Year'] == 2019) & (data['Suicide_Rate_Percent'].notna())]


continent_suicide_rate = data_2019.groupby('Continent_Code')['Suicide_Rate_Percent'].mean().reset_index()


labels = [
    f"{label} ({value:.1f}%)"
    for label, value in zip(continent_suicide_rate['Continent_Code'], continent_suicide_rate['Suicide_Rate_Percent'])
]
sizes = continent_suicide_rate['Suicide_Rate_Percent']
explode = [0.2 if label.startswith('EU') else 0 for label in labels]  


plt.figure(figsize=(10, 8))
plt.pie(sizes, labels=labels, autopct='%1.1f%%', explode=explode, startangle=140, colors=['#ff9999', '#66b3ff', '#99ff99', '#ffcc99', '#c2c2f0', '#ffb3e6'])
plt.title('Percentage of Global Suicides by Continent (2019)', fontsize=16)
plt.show()
No description has been provided for this image

Pokazanie top 10 państw z największym % samobójstwa

In [374]:
europe_data_2019 = data[
    (data['Continent_Code'] == 'EU') & 
    (data['Year'] == 2019) & 
    (data['Suicide_Rate_Percent'].notna())
]


top_10_suicide_rate = europe_data_2019.nlargest(10, 'Suicide_Rate_Percent')[['Country', 'Suicide_Rate_Percent']]

top_10_suicide_rate
Out[374]:
Country Suicide_Rate_Percent
997 Lithuania 26.14
1417 Russian Federation 25.11
1767 Ukraine 21.63
157 Belarus 21.20
937 Latvia 20.12
1537 Slovenia 19.78
747 Hungary 16.65
1407 Romania 16.52
427 Croatia 16.37
807 Ireland 15.44
In [ ]: